package com.thenie.chat.config;

import com.thenie.chat.controller.DialogRandomSocketHandler;
import com.thenie.chat.controller.DialogSocketHandler;
import com.thenie.chat.controller.DialogWorldSocketHandler;
import com.thenie.chat.interceptor.WebSocketInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @Description webSocket配置类
 * @Author thenie
 * @Data 2022/5/28 18:40
 */
@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private DialogSocketHandler dialogSocketHandler;

    @Autowired
    private DialogWorldSocketHandler dialogWorldSocketHandler;

    @Autowired
    private DialogRandomSocketHandler dialogRandomSocketHandler;

    @Autowired
    private WebSocketInterceptor webSocketInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(dialogSocketHandler,"/ws/dialog")
                .addInterceptors(webSocketInterceptor);
        registry.addHandler(dialogWorldSocketHandler,"/ws/world/dialog")
                .addInterceptors(webSocketInterceptor);
        registry.addHandler(dialogRandomSocketHandler,"/ws/random/dialog")
                .addInterceptors(webSocketInterceptor);
    }
}
